package com.snowflake.ecatalog.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.snowflake.ecatalog.entity.CompanyLaunch;

/**
 * 公司信息：包括启动图片、背景图片、公司简介、公司图片、联系信息
 */
public interface CompanyLaunchDao extends PagingAndSortingRepository<CompanyLaunch, Long>,
		JpaSpecificationExecutor<CompanyLaunch> {

	// Page<CompanyLaunch> findByUserId(Long id, Pageable pageRequest);

	@Modifying
	@Query("update CompanyLaunch cl set cl.status = 0 where cl.profile.id = ?1 and cl.type = ?2")
	void disableCompanyLauch(Long profileId, Integer launchType);

	@Modifying
	@Query("update CompanyLaunch cl set cl.status = ?1 where cl.id=?2")
	void changeStatus(Integer status, Long id);

	@Query("select count(cl.id) from CompanyLaunch cl where cl.profile.id=?1 and cl.type=?2 and cl.status=?3")
	long count(Long profileId, Integer launchType, Integer status);

	List<CompanyLaunch> findByProfileIdAndStatusOrderByIdAsc(Long profileId, int status);
}
